package com.oracle.application.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;


@Configuration
public class MQConfig {
    @Bean
public Queue orderDlxQueue(){
    return  new Queue("orderDlxQueue") ;
}
@Bean
public DirectExchange DlxExchange(){
     return  new DirectExchange("DlxExchange");
}
@Bean
public Binding dlxOrderAndDlxExchange(){
        return BindingBuilder.bind(orderDlxQueue()).to(DlxExchange()).with("#");

}
@Bean
public  Queue orderCreateQueue(){
    Map<String,Object>mapProps=new HashMap<>();
    mapProps.put("x-message-ttl",1000*60*2);
    mapProps.put("x-dead-letter-exchange","DlxExchange");
    mapProps.put("x-dead-letter-routing-key","#");
    return new Queue("orderCreateQueue",false,false,false,mapProps);


}
@Bean
public DirectExchange orderDirectExchange(){
     return new DirectExchange("orderDirectExchange");
}
@Bean
public  Binding orderQueueAndorderDirectExchange(){
        return BindingBuilder.bind(orderCreateQueue()).to(orderDirectExchange()).with("order.create");
}
}
